package org.springblade.modules.restaurant.job;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
import com.aizuda.snailjob.client.model.ExecuteResult;
import com.aizuda.snailjob.common.log.SnailJobLog;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.restaurant.service.ICommoditySummaryService;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 商品采购汇总表生成任务
 * @author harry
 * @公众号 Harry技术
 */
@Slf4j
@Component
@AllArgsConstructor
@JobExecutor(name = "commoditySummaryJobExecutor")
public class CommoditySummaryJobExecutor {
	private final ICommoditySummaryService commoditySummaryService;

	public ExecuteResult jobExecute(JobArgs jobArgs) {
		SnailJobLog.REMOTE.info("生成商品采购汇总表,jobArgs:{}", jobArgs);

		Date yesterday = DateUtil.yesterday();
		// 获取开始时间
		DateTime startTime = DateUtil.beginOfDay(yesterday);
		// 获取结束时间
		DateTime endTime = DateUtil.endOfDay(yesterday);
		commoditySummaryService.genCommoditySummary(startTime, endTime);
		return ExecuteResult.success();
	}


//	@PostConstruct
	public void init() {
		log.info("商品采购汇总表生成任务启动");

		Date yesterday = DateUtil.yesterday();
		// 获取开始时间
		DateTime startTime = DateUtil.beginOfDay(yesterday);
		// 获取结束时间
		DateTime endTime = DateUtil.endOfDay(yesterday);
		commoditySummaryService.genCommoditySummary(startTime, endTime);
		commoditySummaryService.genCommoditySummary(startTime, endTime);
	}
}
